首先建立一個伺服器方便之後 telegram 的 hook 來掛載
這邊先從 github 建立一個專案建立基本的專案包含.gitignore和readme

接著打開 terminal 輸入
npm init -y
建立一個進入點的檔案建立最簡單的回應
index.js
var http = require('http');
var server = http.createServer(function (req, res) {
  if (req.url == '/') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.write(JSON.stringify({ message: "Hello World" }));
    res.end();
  }
});
server.listen(3000);
console.log("noder server is start");
然後更改 package.json 裡面的 scripts 追加一個指令
package.json
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
terminal 輸入
npm start
就會看到在 index.js 第 13 行的 console.log 的 "noder server is start"
然後進入遊覽器到以下網址
就可以看到第六行期望吐出的結果
這樣一個簡單的 api 伺服器就完成了